<?php
/**
 * Agg.php class file.
 * @author wudg <544038230@qq.com>
 * @date 2020/11/27- 12:19 下午
 */

namespace common\models\es\dataProvider\comProducts;


use common\models\es\EsComProducts;

class Agg
{
    /**
     * 会员uid
     * @var
     */
    protected $uid;


    /**
     * 店铺mall_id
     * @var
     */
    protected $mall_id;


    public function __construct(int $uid,int $mall_id)
    {
        $this->uid = $uid;
        $this->mall_id = $mall_id;
    }

    /**
     * 获取检索的索引名称
     * @return string
     */
    protected function getIndexName(): string
    {
        return EsComProducts::INDEX;
    }
    /**
     * 获取基础请求参数
     * @return array
     */
    protected function getBodyQuery()
    {
        $params = [];
        if($this->uid)
        {
            $params[] = ['term' => ['uid' => $this->uid]];

        }

        if($this->mall_id)
        {
            $params[] = ['term' => ['mall_id' => $this->mall_id]];
        }

        return $params;
    }


    protected function getBody()
    {
        $baseBody = $this->getBaseBody();

        $bodyQuery = $this->getBodyQuery();
        if ($bodyQuery)
        {
            array_push(
                $baseBody['query']['bool']['filter'],
                ...$bodyQuery
            );
        }
        return $baseBody;
    }
}
